package com.lgd.factoryattendance.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgd.factoryattendance.R;

import java.util.List;

/**
 * @Author lgd
 * @Date 2024/4/26 10:25
 */
public class ElectricGalleryLiatAdapter extends BaseAdapter {
    private Context context;
    private List<List<String>> electricGalleryListItem;

    public ElectricGalleryLiatAdapter(Context context, List<List<String>> electricGalleryListItem) {
        this.context = context;
        this.electricGalleryListItem = electricGalleryListItem;
    }

    @Override
    public int getCount() {
        return electricGalleryListItem == null ? 0 : electricGalleryListItem.size();
    }

    @Override
    public Object getItem(int position) {
        return electricGalleryListItem == null ? null : electricGalleryListItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        ViewHolder viewHolder;
        if (rowView == null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            rowView = inflater.inflate(R.layout.electric_gallery_list, parent, false);
            viewHolder = new ViewHolder();

            viewHolder.tv_electricGalleryName = rowView.findViewById(R.id.tv_electricGalleryName);
            viewHolder.tv_electricMapNumber = rowView.findViewById(R.id.tv_electricMapNumber);
            rowView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) rowView.getTag();
        }
        List<String> galleryShowItem2 = electricGalleryListItem.get(position);
        if (galleryShowItem2 != null && galleryShowItem2.size() >= 2) {
            viewHolder.tv_electricGalleryName.setText(galleryShowItem2.get(0));
            viewHolder.tv_electricMapNumber.setText(galleryShowItem2.get(1));
        }
        //  隔行换色
        if (position % 2 == 0){
            rowView.setBackgroundColor(Color.parseColor("#FFFFFF"));
        }else {
            rowView.setBackgroundColor(Color.parseColor("#F0FFFF"));
        }
        return rowView;
    }
    private static class ViewHolder {
        TextView tv_electricGalleryName;
        TextView tv_electricMapNumber;
    }
}
